﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2_Strategy
{
    /*
      策略模式：定义了算法家族,分别封装起来，让他们之间可以相互替换,此模式让算法的变化，不会影响到使用算法的客户.
         */
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("输入数1:");
            float firstParam = float.Parse(Console.ReadLine());

            Console.WriteLine("输入运算符:");
            string operationType = Console.ReadLine();

            Console.WriteLine("输入数2:");
            float secondParam = float.Parse(Console.ReadLine());//检测输入错误

            float operation = GetResult(firstParam, operationType, secondParam);
            Console.WriteLine("Result:" + operation);

            Console.WriteLine("按任意键退出!");
            Console.ReadKey();
        }

        private static float GetResult(float firstParam, string operationType, float secondParam)
        {
            //策略模式 策略封装。客户不关系具体的算法策略
            OperationContext operation = new OperationContext();
            operation.SwitchOperation(operationType);
            return operation.GetResult(firstParam, secondParam);
        }
    }
}
